package com.whc.config;


import com.whc.properties.AliOssProperties;
import com.whc.utils.AliOssUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author 韦红材
 * @ClassName OssConfiguration
 * @data 2024/09/09 13:39
 * @Version V1.0
 **/
@Configuration
@Slf4j
public class OssConfiguration {

    //加bean是让ioc容器来管理，自动调用这个方法，下面这个注解是为了让该对象单实例，没有这个bean才创建，所有的值都是这样
    @Bean
    @ConditionalOnMissingBean
    public AliOssUtil aliOssUtil(AliOssProperties aliOssProperties){
        log.info("开始创建阿里云oss对象：{}",aliOssProperties);
        return new AliOssUtil(aliOssProperties.getEndpoint(),
                aliOssProperties.getAccessKeyId(),
                aliOssProperties.getAccessKeySecret(),
                aliOssProperties.getBucketName());
    }
}
